#pragma once
#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

class shm_base
{
	bool _has_shm;
	int _size;

	key_t _shm_key;
	int _shm_id;
	void *_memory;
public:
	shm_base(){
		_has_shm = false; 
		_size = 0;

		_shm_key = 0x05001000;
		_shm_id = -1;
		_memory = NULL;
	}
	virtual void whoami(){std::cout <<"base"<< std::endl;}
	
	key_t get_shm_key(){return _shm_key;}
	int   get_shm_id() {return _shm_id;}
	void *get_memory(){return _memory;}
	bool has_init(){return _has_shm;}
	int size(){return _size;}
	void set_size(int i){_size = i;}


	void set_shm_id(int id){_shm_id = id;}
	void *set_memory(void *p){_memory = p;}
	void set_init(bool b){_has_shm = b;}

	void status();

	virtual int init(int serial, int size) = 0;
	virtual int release() = 0;
};

class write_shm: public shm_base
{
public:
	void whoami(){std::cout <<"write_shm"<<std::endl;}

	int init(int ser = 1, int sz = 1024);
	int write_status(int st);
	int write_info(int offsize, const void *src, int len);
	int release();
};

class read_shm: public shm_base
{
	int _size;
public:
	void whoami(){std::cout <<"read_shm"<<std::endl;}
	int init(int ser = 1, int sz = 1024);

	int read_status();
	int copy_info(void *dest, int offsize, int len);
	int read_info(int offsize, int len);
	int release();
};

